package com.huifaapp.mall.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.huifaapp.mall.R;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.api.ObserverCallback;
import com.huifaapp.mall.base.activity.BaseTitleBarActivity;
import com.huifaapp.mall.base.basemvp.IPresenter;
import com.huifaapp.mall.bean.UserBean;
import com.huifaapp.mall.view.ClickTextView;
import com.jakewharton.rxbinding2.view.RxView;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

/**
 * @author: wangZ
 * @date：2017/8/17 17:37
 * FileName：InputInviteCodeActivity
 * @description：填写邀请码
 */

public class InputInviteCodeActivity extends BaseTitleBarActivity {
    public static final String KEY_OPEN_ID = "OPEN_ID";
    public static final String KEY_UNION_ID = "UNION_ID";
    public static final String KEY_NAME = "NAME";
    //    Avatar
    public static final String KEY_AVATAR = "AVATAR"; //头像


    @BindView(R.id.et_invite_code)
    EditText etInviteCode;

    @BindView(R.id.btn_confirm)
    ClickTextView btnConfirm;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_input_invite_code;
    }

    @Override
    protected void initData(Bundle bundle) {
        setTtle("填写邀请码");

        RxView
                .clicks(btnConfirm)
                .map(new Function<Object, Boolean>() {
                    @Override
                    public Boolean apply(Object o) throws Exception {
                        return !TextUtils.isEmpty(etInviteCode.getText().toString());
                    }
                }).subscribe(new Consumer<Boolean>() {
            @Override
            public void accept(Boolean aBoolean) throws Exception {
                if (aBoolean) {
                    reg();
                } else {
                    ToastUtils.showShortSafe("请输入邀请码!");
                }
            }
        });
    }


    @Override
    protected IPresenter onLoadPresenter() {
        return null;
    }

    @OnClick({R.id.btn_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {

            case R.id.btn_confirm:
//                gotoActivity(WebActivity.class);
                break;
        }
    }

    /**
     *
     */
    private void reg() {
//
//        ApiManager
//                .getInstance()
//                .getApiServer()
//                .reg(etInviteCode.getText().toString().trim(), "44533434", "32323",
//                        "http://img4.imgtn.bdimg.com/it/u=4004953177,1659454669&fm=26&gp=0.jpg"
//                        , "空指针")
//                .compose(ApiManager.<UserBean>handlResult())
//                .subscribe(new ObserverCallback<UserBean>(this, true, "注册中") {
//                    @Override
//                    protected void onSuccessful(UserBean resp) {
//                        ToastUtils.showShortSafe("成功");
//                        LogUtils.e(TAG, resp.toString());
//                    }
//
//                    @Override
//                    protected void onError(String code, String errMsg) {
//                        ToastUtils.showShortSafe(errMsg);
//                    }
//                });

    }


}
